/// 用户注册响应模型
/// 根据MyApplication2的RegisterBean设计
class UserRegisterResponse {
  final String status;
  final String message;
  final int? userId;
  final RegisterUserData? data;
  final String? registrationMethod;

  UserRegisterResponse({
    required this.status,
    required this.message,
    this.userId,
    this.data,
    this.registrationMethod,
  });

  /// 从JSON创建实例
  factory UserRegisterResponse.fromJson(Map<String, dynamic> json) {
    return UserRegisterResponse(
      status: json['status'] as String,
      message: json['message'] as String,
      userId: json['user_id'] as int?,
      data: json['data'] != null ? RegisterUserData.fromJson(json['data']) : null,
      registrationMethod: json['registration_method'] as String?,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      'user_id': userId,
      'data': data?.toJson(),
      'registration_method': registrationMethod,
    };
  }

  /// 是否注册成功
  bool get isSuccess => status == 'success';

  @override
  String toString() {
    return 'UserRegisterResponse(status: $status, message: $message, userId: $userId)';
  }
}

/// 注册用户数据模型
class RegisterUserData {
  final int? userid;
  final String? userPhone;
  final String? userEmail;
  final int? userCode;
  final String? username;
  final String? userAvatarUrl;
  final Map<String, dynamic>? userData;
  final int? userAge;
  final String? userGender;
  final String? userSignature;
  final List<String>? userTags;
  final int? userLikes;
  final int? userFollowers;
  final int? userPoints;
  final List<dynamic>? userHobbies;
  final String? userCity;
  final List<String>? userImgUrls;
  final String? userFrequentPlaces;
  final String? userBirthday;
  final int? userLevel;
  final String? status;
  final ExtraData? extraData;
  final String? createdAt;
  final String? lastLogin;
  final String? updatedAt;

  RegisterUserData({
    this.userid,
    this.userPhone,
    this.userEmail,
    this.userCode,
    this.username,
    this.userAvatarUrl,
    this.userData,
    this.userAge,
    this.userGender,
    this.userSignature,
    this.userTags,
    this.userLikes,
    this.userFollowers,
    this.userPoints,
    this.userHobbies,
    this.userCity,
    this.userImgUrls,
    this.userFrequentPlaces,
    this.userBirthday,
    this.userLevel,
    this.status,
    this.extraData,
    this.createdAt,
    this.lastLogin,
    this.updatedAt,
  });

  /// 从JSON创建实例
  factory RegisterUserData.fromJson(Map<String, dynamic> json) {
    return RegisterUserData(
      userid: json['userid'] as int?,
      userPhone: json['userPhone'] as String?,
      userEmail: json['userEmail'] as String?,
      userCode: json['userCode'] as int?,
      username: json['username'] as String?,
      userAvatarUrl: json['userAvatarUrl'] as String?,
      userData: json['userData'] as Map<String, dynamic>?,
      userAge: json['userAge'] as int?,
      userGender: json['userGender'] as String?,
      userSignature: json['userSignature'] as String?,
      userTags: (json['userTags'] as List?)?.cast<String>(),
      userLikes: json['userLikes'] as int?,
      userFollowers: json['userFollowers'] as int?,
      userPoints: json['userPoints'] as int?,
      userHobbies: json['userHobbies'] as List?,
      userCity: json['userCity'] as String?,
      userImgUrls: (json['userImgUrls'] as List?)?.cast<String>(),
      userFrequentPlaces: json['userFrequentPlaces'] as String?,
      userBirthday: json['userBirthday'] as String?,
      userLevel: json['userLevel'] as int?,
      status: json['status'] as String?,
      extraData: json['extraData'] != null ? ExtraData.fromJson(json['extraData']) : null,
      createdAt: json['created_at'] as String?,
      lastLogin: json['last_login'] as String?,
      updatedAt: json['updated_at'] as String?,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'userid': userid,
      'userPhone': userPhone,
      'userEmail': userEmail,
      'userCode': userCode,
      'username': username,
      'userAvatarUrl': userAvatarUrl,
      'userData': userData,
      'userAge': userAge,
      'userGender': userGender,
      'userSignature': userSignature,
      'userTags': userTags,
      'userLikes': userLikes,
      'userFollowers': userFollowers,
      'userPoints': userPoints,
      'userHobbies': userHobbies,
      'userCity': userCity,
      'userImgUrls': userImgUrls,
      'userFrequentPlaces': userFrequentPlaces,
      'userBirthday': userBirthday,
      'userLevel': userLevel,
      'status': status,
      'extraData': extraData?.toJson(),
      'created_at': createdAt,
      'last_login': lastLogin,
      'updated_at': updatedAt,
    };
  }
}

/// 扩展数据模型
class ExtraData {
  final String? token;
  final String? rongcloudUserId;

  ExtraData({
    this.token,
    this.rongcloudUserId,
  });

  /// 从JSON创建实例
  factory ExtraData.fromJson(Map<String, dynamic> json) {
    return ExtraData(
      token: json['token'] as String?,
      rongcloudUserId: json['rongcloud_user_id'] as String?,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'token': token,
      'rongcloud_user_id': rongcloudUserId,
    };
  }
}
